from inital_db import Inital_db
from route import slave,log,machine,monitor
import time
from orm import Request,Status

def select_request():
    for data in Request.select():
        print(data.slave_id,data.temp,data.speed)

def select_service():
    print("服务队列")
    for data in Status.select().where(Status.speed!=0):
        print(data.id,end=' ')
    print()
    print("排队队列")
    for data in Status.select().where((Status.open==1) & (Status.speed==0)):
        print(data.id,end=' ')
    print()

# 初始化数据库
Inital_db()
# 0
# 打开主机空调
machine.open()
# 创建各个房间分机
monitor.init(1,10)
monitor.init(2,15)
monitor.init(3,18)
monitor.init(4,12)
monitor.init(5,14)



# 1
start = time.time()
print('----指令1----')
monitor.open(1)     # 1开机
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 2
start = time.time()
print('----指令2----')
slave.temp_op(24,1)
monitor.open(2)
# select_request()
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))




# 3
start = time.time()
print('----指令3----')
monitor.open(3)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 4
start = time.time()
print('----指令4----')
slave.temp_op(25,2)
monitor.open(4)
monitor.open(5)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))
# 5
start = time.time()
print('----指令5----')
slave.temp_op(27,3)
slave.speed_op(3,5)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 6
start = time.time()
print('----指令6----')
slave.speed_op(3,1)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 7
start = time.time()
print('----指令7----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 8
start = time.time()
print('----指令8----')
slave.temp_op(24,5)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))




# 9
start = time.time()
print('----指令9----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 10
start = time.time()
print('----指令10----')
slave.temp_op(28,1)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 11
start = time.time()
print('----指令11----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))


# 12
start = time.time()
print('----指令12----')
slave.speed_op(2,5)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 13
start = time.time()
print('----指令13----')
slave.speed_op(3,2)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))




# 14
start = time.time()
print('----指令14----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 15
start = time.time()
print('----指令15----')
slave.slave_shutdown(1)
slave.speed_op(1,3)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))


# 16
start = time.time()
print('----指令16----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 17
start = time.time()
print('----指令17----')
slave.slave_shutdown(5)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))


# 18
start = time.time()
print('----指令18----')
slave.speed_op(3,3)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))
# 19
start = time.time()
print('----指令19----')
monitor.open(1)
slave.temp_op(25,4)
slave.speed_op(2,4)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 20
start = time.time()
print('----指令20----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))


# 21
start = time.time()
print('----指令21----')
slave.temp_op(27,2)
slave.speed_op(2,2)
monitor.open(5)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 22
start = time.time()
print('----指令22----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))




# 23
start = time.time()
print('----指令23----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 24
start = time.time()
print('----指令24----')
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 25
start = time.time()
print('----指令25----')
slave.slave_shutdown(1)
slave.slave_shutdown(3)
slave.slave_shutdown(5)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))



# 26
start = time.time()
print('----指令26----')
slave.slave_shutdown(2)
slave.slave_shutdown(4)
time.sleep(1)
select_service()
time.sleep(10-(time.time()-start))

for i in range(1,6):
    print(log.generate_bill(i))

# 关闭工作
for i in range(1,6):
    print(f"关闭分机{i}")
    monitor.destroy(i)

print(f"关闭主机")
machine.close()

